<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/js/jquery.validate.js"></script>
    <script type="text/javascript" src="/js/messages_zh.js"></script>
    <script type="text/javascript">
        function check(type){

            $.ajax({
                url:"/user/check.html",
                method:"post",
                data:"username="+$("#username").val(), //+"&password="


                success:function(json){
                    alert(13);
                    $("#msg").html(json.msg);
                    if(json.status){
                        if(type==1){
                            $("#classForm").submit();
                        }
                    }
                }
            });
        }
  </script>

    <script type="text/javascript">
        $(function(){
            $("#classForm").validate({
                rules:{
                    //字段的name属性：“校验器”
                    //字段的name属性：{“校验器”：“值”，“校验器”：“值”}
                    password:{
                        required:true,
                        digits:true,
                        rangelength:[3,18]	//长度区间
                    },
                    repassword:{
                        required:true,
                        equalTo:'#password'	//必须和某个值相同，与id为pwd相等
                    }
                },
                messages:{
                    password:{
                        required:"密码不能为空",
                        digits:"密码必须由数字组成",
                        rangelength:"密码由3-18位数字组成"
                    },
                    repassword:{
                        required:"确认密码不能为空",
                        equalTo:'确认密码和密码不一致'
                    }
                },
                submitHandler:function(form){
                    form.submit()
                }
            });

        });
    </script>

</head>
<body>
   <form action="/user/regist.html"  method="post" id="classForm">
    <table>
     <tr><td>用户注册</td></tr>
     <tr><td>用户名</td> <td><input type="text" id="username" name="username" onblur="check(0)"><span id="msg" style="color: #f4502d"></span><br /> </td> </tr>
     <tr><td>密码</td> <td><input type="password" id="password" name="password"></td> </tr><span  style="color: blue">${message}</span>
     <tr><td>确认密码</td> <td><input type="password" name="repassword"></td></tr>
        <tr><td><input type="button" value="注册" onclick="check(1)">&nbsp;&nbsp;&nbsp;<a href="/user/search.html"> 去登陆</a></td> </tr>
    </table>
   </form>
</body>
</html>
